<script setup lang="ts">
import PatientsTable from '@renderer/views/patients/components/PatientsTable.vue'
import ConfirmPatientModal from '@renderer/views/patients/components/modal/ConfirmPatientModal.vue'
import { h, provide, ref } from 'vue'
import AddPatientModal from '@renderer/views/patients/components/modal/AddPatientModal.vue'
import { post, postWithAns } from '@renderer/api/http'
import API from '@renderer/api/constant'
import { useScanStore } from '@renderer/store/pinia/scan'
import PatientHistoryImgModal from '@renderer/views/patients/components/modal/PatientHistoryImgModal.vue'
import ChooseExportModal from '@renderer/views/patients/components/modal/ChooseExportModal.vue'

const confirmPatientVisibleRef = ref(false)
const addPatientVisibleRef = ref(false)
const selectedPatientRef = ref({})
const modifiedPatientRef = ref<any>({})
const scanStore = useScanStore()
const updatePatientInfo = () => {
  return new Promise((resolve: any, reject: any) => {
    postWithAns(API.updatePatient, () => resolve(''), modifiedPatientRef.value, () => reject(''))
  })
}
const historyImgModalVisibleRef = ref(false)
const historyImgPatientsId = ref('')
const exportChooseVisibleRef = ref(false)
const showHistoryPatientIds = ref()
const patientListRef = ref([])
const getList = async () => {
  const res: any = await post(API.getPatientList)
  patientListRef.value = res.data
}
provide('patients', {
  patientListRef: patientListRef,
  getPatientList: getList,
  addPatientVisibleRef: addPatientVisibleRef,
  confirmPatientVisibleRef: confirmPatientVisibleRef,

  historyImgModalVisibleRef: historyImgModalVisibleRef,
  showHistoryPatientIds,


  historyImgPatientsId,
  exportChooseVisibleRef,

  selectedPatientRef: selectedPatientRef,
  modifiedPatientRef: modifiedPatientRef,
  updatePatientInfo,
  createPatientInfo: scanStore.createPatientInfo
})

</script>

<template>
  <div class="w-full px-[20px] box-border">
    <patients-table />
    <add-patient-modal v-model="addPatientVisibleRef"></add-patient-modal>
    <confirm-patient-modal v-model="confirmPatientVisibleRef" />
    <patient-history-img-modal v-model="historyImgModalVisibleRef" />

    <choose-export-modal v-model="exportChooseVisibleRef" />
  </div>


</template>

<style scoped>

</style>
